package de.unihannover.hci.portraitquiz.adapter;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import de.unihannover.hci.portraitquiz.PortraitQuiz;
import de.unihannover.hci.portraitquiz.helper.ShapeObstacle;
import de.unihannover.hci.portraitquiz.model.Category;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ObstacleAdapter extends BaseAdapter {
	public static final int COLOR_DISABLED = Color.GRAY;
	public static final int COLOR_ENABLED = Color.WHITE;
	private Context mContext;
	private AssetManager assetManager;
	private PortraitQuiz app;

	public ObstacleAdapter(Context c, PortraitQuiz app) {
		mContext = c;
		this.app = app;
		this.assetManager = c.getAssets();
	}

	public int getCount() {
		return ShapeObstacle.size();
	}

	public Object getItem(int position) {
		
		return ShapeObstacle.getObstacle(position);
	}

	public long getItemId(int position) {
		return ShapeObstacle.getObstacle(position).hashCode();
	}

	// create a new ImageView for each item referenced by the Adapter
	public View getView(int position, View convertView, ViewGroup parent) {
		if(! ShapeObstacle.isInitialized() ){
			ShapeObstacle.initialize(mContext);
		}
		ImageView imageView;
		if (convertView == null) { // if it's not recycled, initialize some
									// attributes
			imageView = new ImageView(mContext);
			int pWidth = (int) Math.round(parent.getWidth() * 0.20);
			
			imageView.setLayoutParams(
					new GridView.LayoutParams(80, 80));
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
			imageView.setPadding(8, 8, 8, 8);
			imageView.setBackgroundColor(COLOR_DISABLED);
		} else {
			imageView = (ImageView) convertView;
		}

		imageView.setImageDrawable(ShapeObstacle.getObstacle(position));
		
		/*
		imageView.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				app.setObstacle(ShapeObstacle.getObstacle(position));
				
			}
		});
		*/
		return imageView;
	}

	// references to our images
	private Integer[] mThumbIds = {

	};
}